<?php

require_once 'common/conn.php';
$result = array();
$db = new DBC();
if (isset($_GET['usercode']) && isset($_GET['task'])) {
    $task = $_GET['task'];
    $usercode = $_GET['usercode'];
    if ($task == "REGISTER" || $task == "PINGJIA") {
        $sql = "SELECT * FROM t_task_record WHERE usercode = '" . $usercode . "' AND task = '" . $task . "'";
        $task_array = $db->fetchData($sql);
        if ($task_array != false && count($task_array) > 0) {
            $result['errorNo'] = "1"; //已经完成
            $result['errorMsg'] = "该任务已经执行过"; //已经完成
        } else {
            $sql = "INSERT INTO t_task_record(usercode,task,createTime) VALUES('" . $usercode . "','" . $task . "',now())";
            if ($db->execute($sql)) {
                $result['errorNo'] = "0"; //首次完成
            } else {
                $result['errorNo'] = "1";
                $result['errorMsg'] = "执行错误";
            }
        }
    } else {
        $sql = "SELECT * FROM t_task_record WHERE usercode = '" . $usercode . "' AND task = '" . $task . "' AND (TO_DAYS(createTime) = TO_DAYS(now()))";
        $task_array = $db->fetchData($sql);
        if ($task_array != false && count($task_array) > 0) {
            $result['everyday'] = "0"; //已经完成
        } else {
            $sql = "INSERT INTO t_task_record(usercode,task,createTime) VALUES('" . $usercode . "','" . $task . "',now())";
            if ($db->execute($sql)) {
                $result['everyday'] = "1"; //首次完成
            } else {
                $result['errorNo'] = "1";
                $result['errorMsg'] = "执行错误";
            }
        }
    }
}

echo json_encode($result);
?>
